import 'reflect-metadata';
import * as path from "path";
import { WsServer, WsClient, HttpServer } from "tsrpc";
import sdk from "./core";
import * as fs from 'fs';
import { env } from "./config";
import { serviceProto as serviceProto_bot } from './shared/api_bot/serviceProto';
import { serviceProto as serviceProto_webClient } from './shared/api_client/serviceProto';
import { ItemType } from "./shared/face/enums";
import { serviceProto as serviceProto_back } from './shared/api_backend/serviceProto';
import { autoTest } from "./autoTest";
export const server_bot = new WsServer(serviceProto_bot, {
    port: env.PORT_BOT,
    json: true,
    logLevel: env.DEV ? 'error' : 'error'
});
export const server_WebClient = new HttpServer(serviceProto_webClient, {
    port: env.PORT_WEB,
    json: true,
    logLevel: env.DEV ? 'error' : 'error',
    https: env.HTTPS ? {
        key: fs.readFileSync(path.join(__dirname, 'ssl', 'privkey.pem')),
        cert: fs.readFileSync(path.join(__dirname, 'ssl', 'fullchain.pem'))
    } : undefined
});
export const server_back = new HttpServer(serviceProto_back, {
    port: env.PORT_BACK,
    json: true,
    logLevel: env.DEV ? 'error' : 'error',
    https: env.HTTPS ? {
        key: fs.readFileSync(path.join(__dirname, 'ssl', 'privkey.pem')),
        cert: fs.readFileSync(path.join(__dirname, 'ssl', 'fullchain.pem'))
    } : undefined
});
async function init() {
    await sdk.init();
    const dir = __dirname;
    await server_bot.autoImplementApi(path.resolve(dir, 'api_bot'));
    await server_bot.start();
    await server_WebClient.autoImplementApi(path.resolve(dir, 'api_client'));
    await server_WebClient.start();

    await server_back.autoImplementApi(path.resolve(dir, 'api_backend'));
    await server_back.start();

    console.log(`服务器启动完成:
bot端口${env.PORT_BOT}
网页端口${env.PORT_WEB}
后台端口${env.PORT_BACK}`);
    // const _autoTest = new autoTest();
    // 执行所有测试用例
    // _autoTest.init();
    // 或者执行指定测试用例（取消注释下面的行，注释上面的行）
    // _autoTest.init('回城测试');
};

init();

